/**
 * Created by Dell on 2017/10/24.
 */
$(function(){

    //背景图的高度
    //$('.main').height($(window).height() - $('.header').height() - $('.footer').height());

   //登录框
    $('.loginBox').css("margin-top",($('.main').height() - $('.loginBox').height())/2);

    var time = new Date().Format('yyyy年MM月dd日');
    $('.sysTime').html(time);


    $('#loginbtn').click(function(){
      var UserId = $('#userName').val();
      var Password = $('#userPwd').val();

      if(UserId ==="admin" && Password === "admin"){
          window.location.href='index.html';
      }else{

      }
    });

    $('#submitBtn').click(function(){
        //var UserId = "gis580";
        //var Password = md5("gis580B1301");
        var UserId = $('#userName').val();
        var Password = $('#userPwd').val();
        var codeId = $('#verifCodeInput').val();
        $.ajax({
            url:config.baseUrl+'/user/userLogin.do',
            type:"post",
            data:{
                userName:UserId,
                passWord:Password,
                code:codeId
            },
            dataType:"json",
	        xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            success:function(data){
                //0 验证码错误，-1：失败；-3：用户不存在；-4：密码错误
                if(data.code === 1){
                    window.location.href='index.html';
                    $.cookie('userInfo',JSON.stringify(data.data))
                }
                else {
                    if(data.code === 0){

                    }else if(data.code === -1){

                    }else if(data.code === -3){

                    }else if(data.code === -4){

                    }
                    $('.notice').html(data.msg);
                    $("#asd").attr("src",config.baseUrl+"/user/getCodeCheck.do?rmd="+new Date().getTime())
                }
            },
        })

    });

    var CODE={
        //初始化化验证码
        initCode:function(){
            $("#asd").attr("src",config.baseUrl+"/user/getCodeCheck.do?rmd="+new Date().getTime())//如果需要点击图片改变图片的内容，则必须添加时间搓
                .click(function(){
                    $(this).attr("src",config.baseUrl+"/user/getCodeCheck.do?rmd="+new Date().getTime());
                });
        }
    };
    CODE.initCode();

    //getCodeCheck()
});
